﻿@using QDT.Core
@model QDT.Common.IPagedList<QDT.Core.Experience.ExpProject>
@{
    Func<int, string> FormatStatus = x =>
        {
            switch (x)
            {
                case 0:
                    return "等待材料";
                case 1:
                    return "进行中";
                case 2:
                    return "还款中";
                case 3:
                    return "已还清";
                default:
                    return "";
            }
        };
    Func<int, string> StatusChange = x =>
        {
            switch (x)
            {
                case 0:
                    return "进行中";
                default:
                    return "";
            }
        };
}
@section HeadSection {

    @Html.IncludeCSS("~/Content/Css/calendar.css")
    @Html.IncludeScript("~/Content/JS/calendar.js")
    @Html.IncludeCSS("~/Content/Css/jquery-calendar.css")
    @Html.IncludeScript("~/Content/JS/jquery-calendar.js")

    <script type="text/javascript">

        function show_detail(projectId) {

            var url = '@Url.Action("ShowDetail")' + '?id=' + projectId;

            showAjaxResult(url, "借款详细统计", 700, 400);
        }

        function change_status(projectId) {

            var url = '@Url.Action("ChangeStatus")' + '?id=' + projectId;

            showAjaxResult(url, "编辑项目状态", 700, 400);
        }

        function repay(projectId) {
            if (confirm('确定还款吗？')) {
                $.ajax({
                    url: '@Url.Action("Refund", "Experience")',
                    data: {
                        id: projectId,
                    },
                    dataType: 'json',
                    type: 'POST',
                    success: function (result) {
                        if (result.Status && result.Status == "true") {
                            alert(result.Message);
                            location.href = location.href;
                        } else {
                            alert(result.Message);
                        }
                    }
                });
            }
        }

    </script>
}

<div class="main_title">
    贷款列表</div>
<div class="blank5">
</div>
<div class="button_row">
    @Html.ActionLink("新增", "Add", new {}, new {@class = "button"})
</div>
<div class="blank5">
</div>
<div class="search_row">
    <form name="search" action="@Url.Action("Index")" method="get">	
        编号：<input type="text" class="textbox" name="projectId" value="@Request.Params["projectId"]" size="8"/>
        贷款名称：<input type="text" class="textbox" name="name" value="@Request.Params["name"]"/>
        贷款状态：
        <select name="dealStatus">
            <option value="" selected="selected">所有状态</option>
            <option value="0">等待材料</option>
            <option value="1">进行中</option>
            <option value="2">还款中</option>
            <option value="3">已还清</option>
        </select>
        开始日期：<input type="text" class="textbox" id="start" name="start" value="@Request.Params["start"]" onfocus=" this.blur(); return showCalendar('start', '%Y-%m-%d', false, false, 'start');" size="8"/>
	    结束日期：<input type="text" class="textbox" id="end" name="end" value="@Request.Params["end"]" onfocus=" this.blur(); return showCalendar('end', '%Y-%m-%d', false, false, 'end');" size="8"/>
        期限：<input type="text" class="textbox" name="repayTime" value="@Request.Params["days"]" size="8"/>
        <input type="submit" class="button" value="搜索"/>
    </form>
</div>
<div class="grid_box">
    <div class="grid_top">
    </div>
    @Html.Grid(Model).Columns(column =>
        {
            column.CheckBox(x => x.ID);
            column.For(x => x.ID).Named("编号").HeaderAttributes(style => "width:50px;");
            column.For(x => Html.ActionLink(x.Name, "Edit", new {id = x.ID})).Named("贷款名称").SortColumnName("Name");
            column.For(x => x.CreateTime).Named("创建时间").HeaderAttributes(style => "width:180px;").SortColumnName("CreateTime");
            column.For(x => x.StartTime).Named("开始时间").HeaderAttributes(style => "width:180px;").SortColumnName("StartTime");
            column.For(x => x.RepayStartTime).Named("还款开始时间").HeaderAttributes(style => "width:180px;").SortColumnName("RepayStartTime");
            column.For(x => x.RepayEndTime).Named("还款时间").HeaderAttributes(style => "width:180px;").SortColumnName("RepayEndTime");
            column.For(x => x.Days + "天").Named("期限").SortColumnName("Days");
            column.For(x => x.BorrowAmount.ToMoney()).Named("借款资金").SortColumnName("BorrowAmount");
            column.For(x => FormatStatus(x.Status)).Named("投标状态").SortColumnName("Status").Encode(false);
            column.Buttons(btns => btns.Add(x => Html.ScriptLink(StatusChange(x.Status), "change_status({0})", x.ID)));
            column.Buttons(btns => btns.Add(x => Html.ActionLink("编辑", "Edit", new {id = x.ID}))
                                       .Add(x => Html.ScriptLink("投标列表", "show_detail({0})", x.ID))
                                       .Add(x => Html.ScriptLink(!x.IsRepay&&x.RepayEndTime<DateTime.Now ? "还款" : "", "repay({0})", x.ID))
                );
        }).Complex(ViewData)
    <div class="grid_foot">
    </div>
</div>
<div class="blank5">
</div>
@Html.Pager(Model)
